package org.dawing.shop.cart.application;

import org.dawing.shop.cart.common.dto.InventoryDto;
import org.dawing.shop.cart.infrastructure.rpc.InventoryService;
import org.dawning.shop.common.domain.cart.CartProduct;
import org.dawning.shop.common.utils.GenerateSku;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 购物车逻辑处理类
 * Created by miou on 2017/6/14 0014.
 */
@Service
public class CartAppService {

    private Logger logger = LoggerFactory.getLogger(CartAppService.class);

    @Autowired
    private InventoryService inventoryService;

    public void checkProductStock(String productId){

        InventoryDto inventoryDto = inventoryService.getInventory(productId);
        logger.info(inventoryDto.getAmount());
    }


    public String getSku(CartProduct cartProduct){
        if(cartProduct == null || cartProduct.getProductId() == null || cartProduct.getProductId().equals("")
                || cartProduct.getAttributes() == null){
            return "";
        }
        return GenerateSku.generateSku(cartProduct.getProductId(),cartProduct.getAttributes());
    }

}
